// JavaScript Document
var searchproduct = "http://218.78.211.188:8080/search/product";
var searchsupplier = "http://218.78.211.188:8080/search/supplier";


var currentpage = 1;
var pagesize = 10;

var keyword = "";
var spec = "";

//日期格式化
function formatDate(date, format) {  
    if (!date) return;  
    if (!format) format = "yyyy-MM-dd";  
    switch(typeof date) {  
        case "string":  
            date = new Date(date.replace(/-/, "/"));  
            break;  
        case "number":  
            date = new Date(date);  
            break;  
    }   
    if (!date instanceof Date) return;  
    var dict = {  
        "yyyy": date.getFullYear(),  
        "M": date.getMonth() + 1,  
        "d": date.getDate(),  
        "H": date.getHours(),  
        "m": date.getMinutes(),  
        "s": date.getSeconds(),  
        "MM": ("" + (date.getMonth() + 101)).substr(1),  
        "dd": ("" + (date.getDate() + 100)).substr(1),  
        "HH": ("" + (date.getHours() + 100)).substr(1),  
        "mm": ("" + (date.getMinutes() + 100)).substr(1),  
        "ss": ("" + (date.getSeconds() + 100)).substr(1)  
    };      
    return format.replace(/(yyyy|MM?|dd?|HH?|ss?|mm?)/g, function() {  
        return dict[arguments[0]];  
    });                  
}  

//复制网址
function CopyUrl() {
    if (navigator.userAgent.indexOf("MSIE") == -1) {
        alert("您的浏览器不支持此功能,请手工复制文本框中内容");
        return false;
    }
    clipboardData.setData('text', document.URL.toString());
    alert("复制成功，请粘贴到你的QQ/MSN上推荐给你的好友！内容如下：" + document.URL.toString());
}

function buildPage(count){
	var page = new Array();
	page.currentpage = Number(currentpage);
	page.pagecount = Math.ceil(Number(count) / Number(pagesize));
	page.start = 1;
	page.end = 9;
	if (Number(page.pagecount) > 9)
	{
		if (Number(currentpage) > 4)
		{
			if (Number(page.pagecount) - Number(currentpage) > 4)
			{
				page.start = Number(currentpage) - 4;
				page.end = Number(currentpage) + 4;
			}
			else
			{
				page.end = Number(page.pagecount);
				page.start = Number(page.end) - 8;
			}
		}						
	}
	else
	{
		page.end = page.pagecount;
	}
	tpl = new jSmart(document.getElementById('page').innerHTML);
	res = tpl.fetch(page);
	$("#pagelist").html(res);	
}

function buildCount(data){
	tpl = new jSmart(document.getElementById('count').innerHTML);
    var res = tpl.fetch(data);
    $("#countinfo").html(res);	
}

function buildSearchCount(data){
	tpl = new jSmart(document.getElementById('searchcount').innerHTML);
    var res = tpl.fetch(data);
    $("#countinfo").html(res);	
}

//材料规格的转换String->Array
function stringToArray(spec)
{
	var ret = new Array();
	if (spec != "" && spec != undefined)
	{
		var props = spec.split(';');
		for (var i = 0; i < props.length; i++)
		{
			if(props[i] != "")
			{
				var propname = props[i].split(':')[0];
				var propvalue = props[i].split(':')[1];
				var prop = new Object();
				prop["propname"] = propname;
				prop["propvalue"] = propvalue;
				ret.push(prop);
			}
		}
	}
	return ret;
}